package com.aisile.article.controller.v1;

import com.aisile.apis.article.ApAuthorControllerApi;
import com.aisile.article.service.ApAuthorService;
import com.aisile.model.article.pojos.ApAuthor;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther:yry
 * @Date:2024/1/2 0002
 * @VERSON:1.0res
 */
@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController implements ApAuthorControllerApi {

    @Autowired
    private ApAuthorService apAuthorService;

    @GetMapping("/findByUserId/{id}")
    @Override
    public ApAuthor findByUserId(@PathVariable("id") Integer id) {
        return apAuthorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId,id));
    }

    @PostMapping("/save")
    @Override
    public ApAuthor save(@RequestBody ApAuthor apAuthor) {
        apAuthorService.save(apAuthor);
        return apAuthor;
    }

    @GetMapping("/findByWmUserId/{wmUserId}")
    @Override
    public ApAuthor findByWmUserId(@PathVariable("wmUserId") Integer wmUserId) {
        return apAuthorService.getOne(
                Wrappers.<ApAuthor>lambdaQuery().eq(
                        ApAuthor::getWmUserId,wmUserId
                )
        );
    }

    @GetMapping("/findone/{id}")
    @Override
    public ApAuthor findById(@PathVariable("id") Integer id) {
        return apAuthorService.getById(id);
    }
}
